import React from 'react';
import { Row, Col, Form, Input, Button, Radio, Select, Tabs, Modal } from 'antd';
const R = require('ramda');
import {connect} from "dva";
import BizParams from '../../../components/commons/BizParams'
import SingleDragger from "../../../components/commons/SingleDragger";
const FormItem = Form.Item;
const TabPane = Tabs.TabPane;
const RadioGroup = Radio.Group;

export default connect(({customerManage}) => ({customerManage}))(
    Form.create({ wrappedComponentRef: true })(class WebsiteCompany extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                open: false
            }
        }

        handleCancel = () => {
            this.props.form.resetFields()
            this.setState({ open: false });
            this.props.handleSearch();
        }

        handleOpen = () => {
            this.setState({ open: true })
        }

        handleConfirm = () => {
            this.props.form.validateFields((errors, values) => {
                let dataSource = R.isNil(this.props.websiteCompanyData) ? {} : this.props.websiteCompanyData
                if (errors) return;

                if(values.approvalresult == 1){
                    values.certificationStatus = "4"
                }else{
                    values.certificationStatus = "5"
                }

                this.props.dispatch({
                    type: "customerManage/updateWebsiteCompany",
                    payload: {
                        id: dataSource.id,
                        ...values,
                        onSuccess: () => {
                            this.handleCancel();
                        }

                    }
                })
            })
        }

        render() {
            const { getFieldDecorator } = this.props.form;
            const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 9 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 12 } } };
            const formItemLayout2 = { labelCol: { span: 5 }, wrapperCol: { span: 19 } };
            let dataSource = R.isNil(this.props.websiteCompanyData) ? {} : this.props.websiteCompanyData;
            let attachments = R.isNil(this.props.attachments) ? {} : this.props.attachments;

            let onOk = dataSource.certificationStatus == "2" ? <Button key="submit" size="large" onClick={this.handleConfirm.bind(this, true)}>确定</Button> : ""
            let footer = [ onOk, <Button key="cancel" size="large" onClick={this.handleCancel.bind(this, true)}>取消</Button> ];

            let module="agreementInfo";
            return (
                <Modal visible={this.state.open} title={"官网企业用户认证详情"} width={900} wrapClassName="vertical-center-modal"
                       footer={footer} onOk={this.handleConfirm} onCancel={this.handleCancel}>
                    <Form>
                        <Tabs tabPosition={'top'}>
                            <TabPane tab="官网待认证企业信息" key="1">
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="客户名称(中文)"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('companyname', {
                                                initialValue: dataSource.companyname
                                            })(
                                                <Input disabled={true} maxLength="200" />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="客户名称（英文）"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('companynameen', {

                                                initialValue: dataSource.companynameen
                                            })(
                                                <Input disabled={true} maxLength="200" />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="客户简称"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('shortname', {

                                                initialValue: dataSource.shortname
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="是否查询企业信用"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('ischeckinfo', {

                                                initialValue: dataSource.ischeckinfo
                                            })(
                                                <RadioGroup disabled={true}>
                                                    <Radio value={"1"}>是</Radio>
                                                    <Radio value={"2"}>否</Radio>
                                                </RadioGroup>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="企业类型"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('companytype', {

                                                initialValue: dataSource.companytype
                                            })(
                                                <BizParams sprCode={"cstType"} style={{ width: '100%' }} blank={true} disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="经营模式"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('businessmodel', {

                                                initialValue: R.isNil(dataSource.businessmodel) ? "" : dataSource.businessmodel + ""
                                            })(
                                                <BizParams sprCode={"businessModel"} style={{ width: '100%' }} blank={true} disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="移动电话"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('mobile', {

                                                initialValue: dataSource.mobile
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="固定电话"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('telephone', {

                                                initialValue: dataSource.telephone
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="邮箱（E-mail）"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('email', {

                                                initialValue: dataSource.email
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="传真"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('tax', {

                                                initialValue: dataSource.tax
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="纳税人识别码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('taxpayerid', {

                                                initialValue: dataSource.taxpayerid
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="组织机构代码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('orgcode', {

                                                initialValue: dataSource.orgcode
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>

                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="工商注册号"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('bussiregno', {

                                                initialValue: dataSource.bussiregno
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="海关注册登记号码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('customsregno', {

                                                initialValue: dataSource.customsregno
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="公司地址(中文)"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('address', {
                                                initialValue: dataSource.address
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="公司地址(英文)"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('addressen', {
                                                initialValue: dataSource.addressen
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="公司网址"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('url', {
                                                initialValue: dataSource.url
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="收件地址"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('recaddress', {
                                                initialValue: dataSource.recaddress
                                            })(
                                                <Input disabled={true} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout} label="法人身份证" hasFeedback>
                                            <SingleDragger url={R.isNil(attachments.corporateIdCard) ? '' : attachments.corporateIdCard.url}
                                                           dataSource={attachments} ref="corporateIdCard"
                                                           module={module} disabled={true} />
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout} label="营业执照" hasFeedback>
                                            <SingleDragger url={R.isNil(attachments.businessLicenses) ? '' : attachments.businessLicenses.url}
                                                           dataSource={attachments} ref="businessLicenses"
                                                           module={module} disabled={true} />
                                        </FormItem>
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                        {dataSource.certificationStatus == "2" ?
                            <Tabs tabPosition={'top'}>
                                <TabPane tab="" key="2">
                                    <Row>
                                        <Col span={12}>
                                            <FormItem
                                                {...formItemLayout}
                                                label="请选择审核结果"
                                                hasFeedback
                                            >
                                                {getFieldDecorator('approvalresult', {
                                                    rules: [{
                                                        required: true, message: '请选择审核结果！',
                                                    }],
                                                    initialValue: "1"
                                                })(
                                                    <Select disabled={false}>
                                                        <Select.Option value="1">审核通过</Select.Option>
                                                        <Select.Option value="2">审核不通过</Select.Option>
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                </TabPane>
                            </Tabs>
                            : ""}
                    </Form>
                </Modal>
            );
        }
    })
)

